//
//  NewMessageController.m
//  20240823
//
//  Created by 张伟 on 2024/8/28.
//

#import "NewMessageController.h"
#import "FSTextView.h"
#import "ContactController.h"

@interface NewMessageController ()
@property (weak, nonatomic) IBOutlet FSTextView *textView;
@property (weak, nonatomic) IBOutlet UIView *bgv;
@property (weak, nonatomic) IBOutlet UITextField *numberTextField;

@end

@implementation NewMessageController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"新消息";
    _textView.placeholder = @"请输入信息内容";
    _bgv.layer.borderWidth = 0.5;
    _bgv.layer.borderColor = [UIColor colorWithHexString:@"e6e6e6"].CGColor;
    _bgv.layer.cornerRadius = 16;
    _bgv.layer.masksToBounds = true;
}

//选择联系人
- (IBAction)selectContactAction:(UIButton *)sender {
    ContactController * vc = ContactController.new;
    vc.title = @"联系人";
    MJWeakSelf
    vc.selectNumberHandle = ^(NSString * _Nonnull number) {
        weakSelf.numberTextField.text = number;
    };
    [self.navigationController pushViewController:vc animated:true];
}

- (IBAction)sendAction:(id)sender {
    
    if (self.numberTextField.text.length == 0) {
        [ZWHud showMessage:@"接受号码不能为空" finishHandle:nil];
        return;
    }
    
    if (self.textView.text.length == 0) {
        [ZWHud showMessage:@"发送内容不能为空" finishHandle:nil];
        return;
    }
    
    NSDictionary * parame = @{
        @"userId":@(UserModel.shared.userId),
        @"to":self.numberTextField.text,
        @"content":[NSString stringWithFormat:@"%@",self.textView.text],
        @"time":[NSString currentTimeString]
    };

    MJWeakSelf
    [NetService requestSendMessage:parame successHandle:^{
        if (weakSelf.loadDataHandle) {
            weakSelf.loadDataHandle();
        }
        [weakSelf.navigationController popViewControllerAnimated:true];
    } fail:^{
        
    }];
}

@end
